package cn.wolfcode.wolf2w.advice;

import cn.wolfcode.wolf2w.exception.LogicException;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理,用来处理我们的逻辑问题和运行时出现的问题
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object LogicExc(Exception e){
        e.printStackTrace();
        return JsonResult.error(JsonResult.CODE_ERROR_PARAM, e.getMessage(), null);
    }

    @ExceptionHandler(RuntimeException.class)
    public Object runtimeException(Exception e){
        e.printStackTrace();
        return JsonResult.error(JsonResult.CODE_ERROR, "系统出现异常了,请赶快联系管理员", null);
    }
}
